<?php


namespace app\index\controller;
use think\Controller ;
use Db;

Class Fall extends  Controller{

    //下载app
    public function App(){

        return view('download_app');
    }

    //下载文件
    public function downloadApp(){
        ob_clean();

        $filename='掌间创课app';

        $filename=iconv("UTF-8","GB2312",$filename);

        $filepath='upload/app.apk';



        //判断路径是否存在

        if(!file_exists($filepath)){
            echo "文件不存在";
            return;
        }

        $fp=fopen($filepath,"r");

        //取得文件大小
        $file_Size=filesize($filepath);

        header("Content-type:application/octet-stream");
        header("Accept-Ranges:bytes");
        header("Accept-Length:".$file_Size);
        header("Content-Disposition: attachment; filename=".$filename);

        $buffer=1024;
        $buffer_count=0;

        while(!feof($fp)&&$file_Size-$buffer_count>0){
            $data=fread($fp,$buffer);
            $buffer_count+=$buffer;
            echo $data;

        }

        fclose($fp);

    }
}
